home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / BODI / METAMAKE.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  12.8 KB  |  522 lines

  1. /*************************************************************************/
  2. /* METAMAKE.C                                 */
  3. /* DATE CREATED:  0/0/0                             */
  4. /* LAST MODIFIED: 09/21/88                         */
  5. /*************************************************************************/
  6.  
  7. /*************************************************************************/
  8. /* HISTORY                                   */
  9. /*                                      */
  10. /* 11/07/89  - Replace all calls of scale_iv() with scaler()         */
  11. /*           disp_neo() - "          "        "         */
  12. /*************************************************************************/
  13.  
  14. #include    <osbind.h>
  15. #include    <gemdefs.h>
  16. #include    "alert.h"
  17.  
  18. #define GDP        11
  19. #define LINE_WIDTH    16
  20. #define MARKER_HEIGHT    19
  21. #define VST_HEIGHT    12
  22. #define VST_POINT    107
  23. #define V_UPDATE    4
  24. #define ARC        2
  25. #define PIE        3
  26. #define CIRCLE        4
  27. #define ELLIPSE        5
  28. #define ELLARC        6
  29. #define ELLPIE        7
  30. #define JUSTEXT        10
  31. #define V_CLEAR        3
  32. #define VGTEXT        8
  33. #define ESCAPE        5
  34. #define V_WRITE        99
  35. #define V_CLIP        129
  36.  
  37. extern    int    contrl[], intin[], ptsin[], intout[], ptsout[];
  38. extern  int    ptsarray[];
  39.  
  40. extern  FDB    page_MFDB;
  41. extern  FDB    laser_MFDB;
  42. extern    int    mhandle;    /* memory driver handle        */
  43. extern     int     phandle;
  44.  
  45. extern  int     scan_xres;
  46. extern  long    scanptr;
  47.  
  48. extern  int    print_flag;
  49. extern  char *get_lcmem();
  50. extern  int     hpage_size;
  51. extern  int     vpage_size;
  52. extern  char    fbuffer[];
  53. extern  char *dpath1;
  54. extern  char *dpath2;
  55. extern  char *dpath3;
  56. extern  char *dpath4;
  57. extern  int scan_xres,scan_yres;
  58. extern  int mxres,myres;
  59. extern  unsigned long page_ptr;
  60.  
  61. extern  int mnumfnt;
  62. extern  int pnumfnt;
  63.  
  64. int font_flag;
  65.  
  66.  
  67. long readswap();
  68.  
  69. int    meta_wd, meta_ht;
  70. int    formw, formy;
  71.  
  72. int logo[16] = {
  73.          0x05a0,0x5a0,0x5a0,0x5a0,0xdb0,0x0db0,0x1db8,0x399c,
  74.          0x799e,0x718e,0x718e,0x6186,0x4182,0,0,0
  75.            };
  76.  
  77. long    readswap(handle, length, buffer)
  78. long    length;
  79. int    handle;
  80. register char    *buffer;
  81. {
  82.     register long    count;
  83.         long bytes_read;
  84.     char    temp;
  85.  
  86.     bytes_read = Fread(handle,length,buffer);
  87.     for (count = 0;count < bytes_read;count += 2) {
  88.       temp         = buffer[count];
  89.       buffer[count]  = buffer[count+1];
  90.       buffer[count+1]= temp;
  91.     }
  92.     return(bytes_read);
  93. }
  94.  
  95. mtadjx(x)
  96. int    x;
  97. {
  98.     return((int)(((long)x * (long)formw) / (long)meta_wd));
  99. }
  100.  
  101. mtadjy(y)
  102. int    y;
  103. {
  104.     return((int)(((long)y * (long)formy) / (long)meta_ht));
  105. }
  106.  
  107.  
  108. /********************************/
  109. /*    MetaFile display    */
  110. /********************************/
  111. meta_make(handle, mx, my,mw,mh)
  112. register int    handle;
  113. int    mx, my, mw, mh;
  114. {
  115.    int  x1,y1,wid,ht;
  116.    register int    i;
  117.    int  dummy, header_length;
  118.    int    pagex, pagey, llx, lly, urx, ury;
  119.    register int  thandle;
  120.  
  121.    /*    first word is 0fffh    */
  122.    Fread(handle, 2L, &dummy);
  123.  
  124.    /*    read length of header in words    */
  125.    readswap(handle, 2L, &header_length);
  126.  
  127.    /*    skip over version number    */
  128.    Fread(handle, 2L, &dummy);
  129.  
  130.    /*    get scaling factors    */
  131.    readswap(handle, 2L, &dummy);    /* rc_ndc not used    */
  132.    readswap(handle, 2L, &dummy);    /* minx not used    */
  133.    readswap(handle, 2L, &dummy);    /* miny not used    */
  134.    readswap(handle, 2L, &dummy);    /* maxx not used    */
  135.    readswap(handle, 2L, &dummy);    /* maxy not used    */
  136.    readswap(handle, 2L, &pagex);
  137.    readswap(handle, 2L, &pagey);
  138.    readswap(handle, 2L, &llx);
  139.    readswap(handle, 2L, &lly);
  140.    readswap(handle, 2L, &urx);
  141.    readswap(handle, 2L, &ury);
  142.  
  143.    /*    seek past the header    */
  144.    Fseek((long)header_length * 2L, handle, 0);
  145.  
  146.    meta_wd    = urx - llx + 1;
  147.    meta_ht    = lly - ury + 1;
  148.  
  149.  
  150.    if(print_flag== 1)  /* Convert to pixels and scale  */
  151.    {
  152.         mutolas(mx,my,&x1,&y1);
  153.         mutolas(mw,mh,&wid,&ht);
  154.         thandle = phandle;
  155.    }
  156.    else if(!print_flag)
  157.    {
  158.         mutopage(mx,my,&x1,&y1,0);
  159.         mutopage(mw,mh,&wid,&ht,1);
  160.         thandle = mhandle;
  161.    }
  162.    else if(print_flag == 2)
  163.    {                    /* Special case for repel image */
  164.     mutomem(mx,my,&x1,&y1);
  165.     mutomem(mw,mh,&wid,&ht);
  166.     thandle = mhandle;
  167.     GDvq_extnd(mhandle,0,intout,scan_xres,scan_yres,&scanptr);
  168.    }
  169.  
  170.    formw = wid;
  171.    formy = ht;
  172.  
  173.    for (;;) {
  174.     /*    read opcode    */
  175.     readswap(handle, 2L, &contrl[0]);
  176.     if (contrl[0]==0xFFFF) break;
  177.  
  178.     /*    read vertex count    */
  179.     readswap(handle, 2L, &contrl[1]);
  180.       
  181.     /*    read integer count    */
  182.     readswap(handle, 2L, &contrl[3]);
  183.  
  184.     /*    read sub-opcode        */
  185.     readswap(handle, 2L, &contrl[5]);
  186.       
  187.     /*    read in points and swap    */
  188.     readswap(handle, (long)contrl[1] * 4L, ptsin);
  189.  
  190.     /*    transform co-ords    */
  191.     switch (contrl[0]) {
  192.     case GDP:
  193.        switch (contrl[5]) {
  194.        case CIRCLE:
  195.        case ARC:
  196.        case PIE:
  197.        case ELLIPSE:
  198.        case ELLPIE:
  199.        case ELLARC:
  200.        case JUSTEXT:
  201.         ptsin[0] = x1 + mtadjx(ptsin[0]-llx);
  202.         ptsin[1] = y1 + mtadjy(ptsin[1]-ury);
  203.         for (i = 2;i < (contrl[1] * 2);i += 2) {
  204.            ptsin[i]   = mtadjx(ptsin[i]  );
  205.            ptsin[i+1] = mtadjy(ptsin[i+1]);
  206.         }
  207.         break;
  208.        default:
  209.         goto others;
  210.        }
  211.        break;
  212.     case LINE_WIDTH:
  213.     case MARKER_HEIGHT:
  214.     case VST_HEIGHT:
  215.        ptsin[0] = mtadjx(ptsin[0]);
  216.        ptsin[1] = mtadjy(ptsin[1]);
  217.        break;
  218.     default:
  219.     others:
  220.        for (i = 0;i < (contrl[1] * 2);i += 2) {
  221.         ptsin[i]   = x1 + mtadjx(ptsin[i]  -llx);
  222.         ptsin[i+1] = y1 + mtadjy(ptsin[i+1]-ury);
  223.        }
  224.        break;
  225.     }
  226.  
  227.     /*    read in ints and swap    */
  228.     readswap(handle, (long)contrl[3] * 2L, intin);
  229.  
  230.     /*    for scaled image, change vst_point to vst_height
  231.         and transform sizes    */
  232.     if (contrl[0] == VST_POINT) {
  233.       contrl[0] = VST_HEIGHT;
  234.       contrl[1] = 1;
  235.       contrl[3] = 0;
  236.       ptsin[0]  = 0;
  237.       ptsin[1]  = (int)(((long)intin[0] *3L* (long)formy)/ (long)pagey);
  238.     }
  239.  
  240.     if((contrl[0] != V_UPDATE) && (contrl[0] != V_CLEAR) &&
  241.            (contrl[0] != V_CLIP))
  242.     {
  243.           if(
  244.               ((contrl[0] == VGTEXT) ||
  245.           ((contrl[0] == GDP) && (contrl[5] == JUSTEXT)))
  246.             )
  247.           {
  248.          if(((phandle == thandle) && pnumfnt) ||
  249.             ((mhandle == thandle) && mnumfnt) )
  250.          {
  251.               contrl[6] = thandle;
  252.            vdi();
  253.          }
  254.           }
  255.           else
  256.       {
  257.          if(contrl[0] == ESCAPE)
  258.          {
  259.         if(contrl[5] != V_WRITE)
  260.         {
  261.                contrl[6] = thandle;
  262.                vdi();
  263.         }
  264.              }
  265.              else
  266.              {    
  267.            contrl[6] = thandle;
  268.            vdi();
  269.          }
  270.           }
  271.     }
  272.    }
  273.    if(print_flag == 2)
  274.     GDvq_extnd(mhandle,0,intout,mxres,myres,&page_ptr);    
  275.  
  276.    vsf_udpat(thandle,logo,1);        /* user pattern to Atari Logo*/
  277.    vsl_type(thandle,1);            /* Line type to solid         */
  278.    vsl_width(thandle,1);        /* Line width to 1         */
  279.    vsl_ends(thandle,0,0);        /* end points to squares...  */
  280.  
  281.    vswr_mode(thandle,1);        /* set to replace...         */
  282.    vst_color(thandle,1);        /* set text, fill and line   */
  283.    vsf_color(thandle,1);        /* color index to 1         */
  284.    vsl_color(thandle,1);   
  285. }
  286.  
  287.  
  288.  
  289. /********************************/
  290. /*    IMG File display    */
  291. /********************************/
  292. disp_img(filename,x1,y1,x2,y2)
  293. register char    *filename;
  294. int    x1,y1,x2,y2;
  295. {
  296.     int     thandle;
  297.     register int    i;
  298.     int    tx1,ty1,tx2,ty2;
  299.  
  300.        if(print_flag == 1)  /* Convert to pixels and scale  */
  301.        {
  302.            mutolas(x1,y1,&tx1,&ty1);
  303.            mutolas(x2,y2,&tx2,&ty2);
  304.            thandle = phandle;
  305.        }
  306.        else if(!print_flag)
  307.        {
  308.            mutopage(x1,y1,&tx1,&ty1,0);
  309.            mutopage(x2,y2,&tx2,&ty2,0);
  310.            thandle = mhandle;
  311.        }
  312.     else if(print_flag == 2)
  313.         {
  314.        mutomem(x1,y1,&tx1,&ty1);
  315.        mutomem(x2,y2,&tx2,&ty2);
  316.        thandle = mhandle;
  317.        GDvq_extnd(mhandle,0,intout,scan_xres,scan_yres,&scanptr);       
  318.         }
  319.     
  320.     contrl[0] = 5;
  321.     contrl[1] = 2;
  322.     contrl[2] = 0;
  323.     contrl[4] = 0;
  324.     contrl[5] = 23;
  325.     contrl[6] = thandle;
  326.     intin[0]  = intin[1] = intin[2] = intin[3] = intin[4] = 0;
  327.  
  328.     for (i = 0;filename[i];intin[i+5] = (int)filename[i++]);
  329.     contrl[3] = i + 5;
  330.  
  331.     ptsin[0]  = tx1;
  332.     ptsin[1]  = ty1;
  333.     ptsin[2]  = tx2;
  334.     ptsin[3]  = ty2;
  335.     vdi();
  336. /*    if(print_flag == 0 || print_flag == 2)*/
  337.         v_clear_disp_list(mhandle);        /* Frees up image buffers */
  338.     if(print_flag == 2)
  339.         GDvq_extnd(mhandle,0,intout,mxres,myres,&page_ptr);
  340.  
  341. }
  342.  
  343.  
  344. /********************************/
  345. /*    NEO File display    */
  346. /********************************/
  347. disp_neo(grbuf,cobuf,x1,y1,w,h)
  348. unsigned char    *grbuf;
  349. unsigned    *cobuf;
  350. int    x1, y1;
  351. int     w,h;
  352. {
  353.         int tmp;
  354.  
  355.     struct    {
  356.       unsigned char    *sMF;    /* +00 Source Memory Form base address    */
  357.       unsigned    swb;    /* +04 Width of memory form (in bytes)    */
  358.       unsigned    sx;    /* +06 Xmin of source rectangle        */
  359.       unsigned    sy;    /* +08 Ymin of source rectangle        */
  360.       unsigned    sw;    /* +10 Width    (in pixels)        */
  361.       unsigned    sh;    /* +12 Height    (in pixels)        */
  362.  
  363.       unsigned long    dMF;    /* +14 Target Memory Form base address    */
  364.       unsigned    dwb;    /* +18 Width of memory form (in bytes)    */
  365.       unsigned    dx;    /* +20 Xmin of target rectangle        */
  366.       unsigned    dy;    /* +22 Ymin of target rectangle        */
  367.       unsigned    dw;    /* +24 Width    (in pixels)        */
  368.       unsigned    dh;    /* +26 Height    (in pixels)        */
  369.     }    neo;
  370.  
  371.     neo.sMF    = grbuf;
  372.     neo.swb    = 160;
  373.     neo.sx    = 0;
  374.     neo.sy    = 0;
  375.     neo.sw    = 320;
  376.     neo.sh    = 200;
  377.  
  378.     if((x1 >= hpage_size) || /* If the object is off the page, then */
  379.        (y1 >= vpage_size) || /* Don't print it...                   */
  380.        ((x1 + w) <= 0)    ||
  381.            ((y1 + h) <= 0)
  382.           )return;
  383.  
  384.     if(x1 < 0)         /* Otherwise, clip them...             */
  385.     {
  386.         neo.sx = scaler(abs(x1),320,w);
  387.         w  -= abs(x1);
  388.         x1 = 0;
  389.         neo.sw -= neo.sx;
  390.     }
  391.             
  392.     if((x1 + w) > hpage_size) 
  393.     {
  394.             tmp = (x1 + w) - hpage_size; 
  395.         neo.sw -= scaler(tmp,320,w);
  396.         w -= tmp;
  397.       }
  398.         
  399.         if(y1 < 0)
  400.     {
  401.             neo.sy = scaler(abs(y1),200,h);
  402.         h -= abs(y1);
  403.         y1 = 0;
  404.         neo.sh -= neo.sy;
  405.     }
  406.  
  407.     if((y1 + h) > vpage_size)
  408.     {
  409.             tmp = (y1 + h) - vpage_size;
  410.           neo.sh -= scaler(tmp,200,h);
  411.         h -= tmp;
  412.     }
  413.     
  414.         if(print_flag == 1)  /* Convert to pixels and scale  */
  415.         {
  416.             mutolas(x1,y1,&neo.dx,&neo.dy);
  417.             mutolas(w,h,&neo.dw,&neo.dh);
  418.            neo.dMF = laser_MFDB.fd_addr;
  419.            neo.dwb = ((laser_MFDB.fd_w + 15)/16)*2;
  420.            neo.dw--;
  421.         }
  422.         else if(!print_flag)
  423.         {
  424.             mutopage(x1,y1,&neo.dx,&neo.dy,0);
  425.             mutopage(w,h,&neo.dw,&neo.dh,1);
  426.            neo.dMF    = page_MFDB.fd_addr;
  427.            neo.dwb = ((page_MFDB.fd_w + 15)/16)*2;
  428.            neo.dw--;
  429.         }
  430.     else if(print_flag == 2)
  431.     {
  432.            mutomem(x1,y1,&neo.dx,&neo.dy);
  433.            mutomem(w,h,&neo.dw,&neo.dh);
  434.            neo.dMF  = scanptr;
  435.                neo.dwb = ((scan_xres + 15)/16)*2;
  436.            neo.dw--;
  437.     }
  438.  
  439.     haftone(&neo,cobuf);
  440. }
  441.  
  442.  
  443.  
  444. /****************************************************************
  445. *    Function Name :        insert_graphic()        *
  446. *    Desc :    This routine handles graphics file insertion.    *
  447. *    Calling convention :    insert_graphic(cmd_ptr,arg)    *
  448. *        unsigned char    cmd_ptr : pointer to command    *
  449. *        unsigned    arg : argument value        *
  450. ****************************************************************/
  451. insert_graphic()
  452. {
  453.     unsigned char    *gfile;
  454.     long    grbuf;
  455.     int    cobuf[16];
  456.     register int    fid;
  457.     int    w, h, pw, ph;
  458.  
  459.     
  460.    gfile    = &ptsarray[5];      /* graphics image DOS filename    */
  461.    strcpy(fbuffer,dpath3);
  462.    strcat(fbuffer,gfile);
  463.    if (((fid = Fopen(fbuffer,0)) <= 0)) 
  464.    {
  465.       alert_cntre(ALERT16);
  466.       return;
  467.    }
  468.    switch((int)ptsarray[4]) {
  469.     case 0    :                /* NEOchrome image    */
  470.         grbuf = (long)get_lcmem(32000L);
  471.         if(!grbuf)
  472.         {
  473.            alert_cntre(ALERT32);
  474.            Fclose(fid);
  475.            return;
  476.         }
  477.         Fseek(4L,fid,0);        /* skip first 4 bytes    */
  478.         Fread(fid,32L,cobuf);        /* read color buffer    */
  479.         Fseek(128L,fid,0);        /* skip 128bytes header */
  480.         Fread(fid,32000L,grbuf);    /* read file bit block    */
  481.         disp_neo(grbuf,cobuf,ptsarray[0],ptsarray[1],
  482.               ptsarray[2] - ptsarray[0],
  483.               ptsarray[3] - ptsarray[1]);
  484.         free(grbuf);            /* free graphics buffer */
  485.         break;
  486.     case 1    :                /* IMG (Gem bit) image    */
  487.         Fseek(8L,fid,0);        /* skip 8 bytes header    */
  488.         Fread(fid,2L,&pw);        /* read pixel micron W    */
  489.         Fread(fid,2L,&ph);        /* read pixel micron H    */
  490.         Fread(fid,2L,&w);        /* read width  of page    */
  491.         Fread(fid,2L,&h);        /* read height of page    */
  492.         disp_img(fbuffer,ptsarray[0],ptsarray[1],
  493.              ptsarray[2],ptsarray[3]);
  494.         break;
  495.     case 2    :                /* Gem Metafile image    */
  496.         meta_make(fid,ptsarray[0],ptsarray[1],
  497.               ptsarray[2] - ptsarray[0],
  498.               ptsarray[3] - ptsarray[1]);
  499.         break;
  500.  
  501.     case 3  :                /* PI1 Degas Low Rez    */
  502.         grbuf = (long)get_lcmem(32000L);
  503.         if(!grbuf)
  504.         {
  505.            alert_cntre(ALERT32);
  506.            Fclose(fid);
  507.            return;
  508.         }
  509.         Fseek(2L,fid,0);        /* skip first 2 bytes    */
  510.         Fread(fid,32L,cobuf);        /* read color buffer    */
  511.         Fseek(34L,fid,0);        /* skip 34 bytes header */
  512.         Fread(fid,32000L,grbuf);    /* read file bit block    */
  513.         disp_neo(grbuf,cobuf,ptsarray[0],ptsarray[1],
  514.               ptsarray[2] - ptsarray[0],
  515.               ptsarray[3] - ptsarray[1]);
  516.         free(grbuf);            /* free graphics buffer */
  517.         break;
  518.    }
  519.    Fclose(fid);                /* close graphics file    */
  520.  
  521. }
  522.